package org.lmind.example.util.common;

import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

public class CollectionConvert {

	@SuppressWarnings("rawtypes")
	public static <T> T[] asArray(Collection collection, Class<T[]> clazz) {
		return (T[])Arrays.copyOf(collection.toArray(), collection.size(), clazz);
	}
	
	
	
	public static <T> Set<T> asSet(Enumeration<T> enumeration) {
		HashSet<T> set = new HashSet<T>();
		while (enumeration.hasMoreElements()) {
			set.add(enumeration.nextElement());
		}
		return set;
	}
}
